#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int b[N],c[N],f[1000010],v[1000010];
void init()
{
memset(v, 0x3f,sizeof v);
v[1] = 0;
for(int i = 1; i <= 1000; i ++)
{
for(int j = 1; j <= i ;j ++)
{
if(i+i/j<=1000)v[i+i/j] = min(v[i+i/j],v[i]+1);
}
}
}
int main()
{
int T;
cin>>T;
init();
while(T--)
{
int n , k;
cin>>n>>k;
memset(f,0,sizeof f);
for(int i = 1; i <= n; i ++)cin>>b[i];
for(int i = 1; i <= n; i++)cin>>c[i];
for(int i = 1; i <= n; i ++)
for(int j = k; j>=v[b[i]];j--)
{
f[j] = max(f[j], f[j-v[b[i]]] + c[i]);
}
cout<<f[k]<<endl;
}
}
975C - Valhalla Siege | 518B - Tanya and Postcard |
514B - Han Solo and Lazer Gun | 898B - Proper Nutrition |
9C - Hexadecimal's Numbers | 1265B - Beautiful Numbers |
745A - Hongcow Learns the Cyclic Shift | 873A - Chores |
1754B - Kevin and Permutation | 1547D - Co-growing Sequence |
1754D - Factorial Divisibility | 1117B - Emotes |
412B - Network Configuration | 845B - Luba And The Ticket |
1732A - Bestie | 389A - Fox and Number Game |
1732B - Ugu | 1100B - Build a Contest |
1181B - Split a Number | 1313B - Different Rules |
1736D - Equal Binary Subsequences | 1754A - Technical Support |
26B - Regular Bracket Sequence | 699A - Launch of Collider |
474D - Flowers | 1016A - Death Note |
1335C - Two Teams Composing | 1167C - News Distribution |
813C - The Tag Game | 1130C - Connect |